#pragma once

struct MainMenuEntry
{
	ui32 x;
	ui32 y;
	ui32 id;
	std::wstring wszText;
	ui32 color;

	bool operator < (MainMenuEntry& m2) {
		bool isSmaller = wcscmp(wszText.c_str(), m2.wszText.c_str()) < 0;
		Log::Print("Smaller: %u\n", isSmaller);
		return isSmaller;
	}
};

class MainMenu : public Singleton<MainMenu>
{
	VScrollbar<MainMenu>* m_locScroll;
	UIButton<MainMenu>* m_back;
	UILabel* m_adtHover;
	UILabel* m_minMapHelp1;
	UILabel* m_minMapHelp2;
	MiniMap* m_curMiniMap;
	std::vector<MainMenuEntry> mEntries;
	std::map<wchar_t, std::vector<MainMenuEntry>> mSortedEntries;
	ui32 m_miniMap;
	float m_scaleFactor;
	Vertex2F m_relFactor;
	Vertex2F m_mouseLast;
	ApplicationState mLastState;
	FontBatch mBatch;
	CFont mEntryFont;
	IDirect3DTexture9* mBackgTexture;
	void loadTexture();
	ui32 calcMenuSize();
	MainMenuEntry* getEntryForPos(ui32 x, ui32 y);
	void colorMenuEntries(ui32 x, ui32 y);
public:
	MainMenu();
	void Render();
	void OnButtonPressed(UIButton<MainMenu>* pButton);
	void OnMouseMove(Vertex2F pos, bool rButton);
	bool OnMouseClick(Vertex2F pos);
	void MouseWheel(i16 up);
	void BeforeReset();
	void OnReset();
};

#define sMainMenu (*MainMenu::GetInstance())